# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models


class Log(models.Model):
    """Nginx Log model"""
    id = models.AutoField(primary_key=True)
    request_ip = models.CharField(max_length=15)
    some_str = models.CharField(max_length=255, null=True)
    request_time = models.CharField(max_length=30)
    request_method = models.CharField(max_length=10)
    request_url = models.CharField(max_length=255, db_index=True)
    http_version = models.CharField(max_length=10)
    host = models.CharField(max_length=255)
    status_code = models.CharField(max_length=3)
    content_length = models.PositiveIntegerField(default=0)
    refer = models.CharField(max_length=255, null=True)
    user_os = models.CharField(max_length=30)
    app_version = models.CharField(max_length=30, null=True)
    user_ip = models.CharField(max_length=80, db_index=True)
    backend_address = models.CharField(max_length=30, null=True)
    backend_code = models.CharField(max_length=3, null=True)
    backend_duration = models.CharField(max_length=10, null=True)
    response_duration = models.FloatField(default=0)

    class Meta:
        db_table = 'nginx_log'
        verbose_name = 'NginxLog'
        verbose_name_plural = 'NginxLogs'
        index_together = ['user_os', 'app_version']

    # @property
    # def url_prefix_get(self):
    #     """获取URL前缀"""
    #     url_prefix = self.request_url.split('?')[0]
    #     return url_prefix
